﻿using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace MagicSir
{
    public static class MagicSirApp
    {
        public static IServiceProvider ServiceProvider { get; internal set; }
        public static IHttpContextAccessor HttpContextAccessor { get; internal set; }
        public static HttpContext HttpContext { get { return HttpContextAccessor.HttpContext; } }
        static IConfiguration _configuration;
        public static IConfiguration Configuration
        {
            get
            {

                if (_configuration == null)
                {
                    _configuration = GetService<IConfiguration>();
                }
                return _configuration;
            }
        } // { get; internal set; }

        static string _environment = "";
        public static string Environment
        {
            get
            {
                if (string.IsNullOrEmpty(_environment))
                {
                    _environment = System.Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? System.Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT") ?? "";
                }
                return _environment;
            }
        }
        public static T GetService<T>()
        {
            return ServiceProvider.GetService<T>();
        }
        public static object GetService(Type serviceType)
        {
            return ServiceProvider.GetService(serviceType);
        }
        public static IEnumerable<T> GetServices<T>()
        {
            return ServiceProvider.GetServices<T>();
        }
    }
}
